package com.tzbank.common.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.common.service.CommonService;
import com.tzbank.common.service.ThemeService;
import com.tzbank.redis.RedisUtils;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 公共模块
 * @author liweibin
 *
 */
@Slf4j
@RestController
@RequestMapping("common")
public class CommonController {

	@Autowired
	private CommonService commonService;

	@Autowired
	private ThemeService themeService;

	@PostMapping(value="/theme")
	public String theme(@RequestBody Map<String,String> reqBody) {
		return themeService.getThemePageFlow(reqBody);
	}
    
    /**
	 * 银行列表接口
	 * @return
	 */
    @PostMapping(value = "/bank")
    @ApiOperation(value = "银行列表接口", notes = "银行列表接口")
    public Map<String,Object> bankList() {
    	Map<String,Object> map = new HashMap<String,Object>();
    	map.put("banklist", commonService.getListBank());			//redis 数据取出来转JSONARR
        return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), map);
    }
    
    /**
	 * 热门银行列表接口
	 * @return
	 */
    @PostMapping(value = "/hotbank")
    @ApiOperation(value = "热门银行列表接口", notes = "热门银行列表接口")
    public Map<String,Object> hotbankList() {
    	Map<String,Object> map = new HashMap<String,Object>();
    	map.put("banklist", commonService.getListHotBank());		//redis 数据取出来转JSONARR
        return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), map);
    }
    
    /**
	 * 获取字典集合
	 */
    @PostMapping(value = "/dict")
    @ApiOperation(value = "字典接口", notes = "字典接口")
	public Map<String,Object> getListDict(@RequestBody Map<String,String> reqBody) {
    	return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), commonService.getListDict());
	}
    /**
	 * 字典集合重置
	 */
    @PostMapping(value = "/removeDict")
    @ApiOperation(value = "字典接口", notes = "字典接口")
	public Map<String,Object> removeDict() {
    	RedisUtils.deleteByKey("dict");
    	return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}
    
    @GetMapping("clearCache")
    @ApiOperation(value="清除redis缓存",notes="清除缓存")
    public Map<String,Object> clearCache(){
    	RedisUtils.deleteByKey("dict");
    	RedisUtils.deleteByKey("banklist");
    	RedisUtils.deleteByKey("config");

    	return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);

    }
    
    /**
	 * 获取区域集合
	 */
    @PostMapping(value = "/area")
    @ApiOperation(value = "地区接口", notes = "地区接口")
	public Map<String,Object> getListArea() {
    	return commonService.getListArea();
	}

    /**
	 * 获取营业网点
	 * @param reqBody
	 * llz
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/getOutlets")
	@ApiOperation(value = "获取营业网点Json数据", notes = "获取营业网点Json数据")
	public Map<String, Object> getOutlets(@RequestBody Map<String, String> reqBody) {
		return commonService.getOutlets(reqBody);
	}

}
